#!/bin/bash
ROOT=$(dirname $(readlink -f "$0"))   # ROOT 指向 /path/to/rpa_api/app
PROJECT_ROOT=$(dirname "$ROOT")        # 上一级目录，即 /path/to/rpa_api



echo PROJECT_ROOT: $PROJECT_ROOT
cd "$PROJECT_ROOT"


./wait-for-it.sh "${MYSQL_HOST:-mysql}:${MYSQL_PORT:-3306}" --timeout=30 --strict -- echo "[$(date '+%Y-%m-%d %H:%M:%S')] MySQL is up"
./wait-for-it.sh "${REDIS_HOST:-redis}:${REDIS_PORT:-6379}" --timeout=30 --strict -- echo "[$(date '+%Y-%m-%d %H:%M:%S')] Redis is up"


# 启动 Celery beat
celery -A app.celery_worker beat --loglevel=info --logfile=/app/logs/celery-beat.log &

# 启动 Celery worker
celery -A app.celery_worker worker --loglevel=info &

wait